package view.panel.prompt
{
	import control.panel.prompt.IPromptPanelSelectCombineCardsControl;
	
	import flash.events.MouseEvent;
	
	import global.GameState;
	
	import utils.ColorTool;
	import utils.DisplayTool;
	
	import view.panel.AbsPanel;

	public class PromptSelectCombineCardsPanel extends AbsPanel
	{
		private var cards:Array;
		private var selectCombines:Array = [];
		
		public function PromptSelectCombineCardsPanel(panelControl:IPromptPanelSelectCombineCardsControl)
		{
			super(panelControl);
			ColorTool.dropShadow(this);
		}
		
		public function updateCombineCards(combineCards:Array):void
		{
			DisplayTool.removeAllChild(this);
			var cardDatas:Array;
			var selectCombine:SelectCombine;
			var lastSelectCombine:SelectCombine;
			for (var i:String in combineCards)
			{
				cardDatas = combineCards[i];
				selectCombine = new SelectCombine(panelControl as IPromptPanelSelectCombineCardsControl);
				selectCombine.showCards(cardDatas);
				selectCombines.push(selectCombine);
				
				if (lastSelectCombine)
				{
					selectCombine.x = 6 + lastSelectCombine.width + lastSelectCombine.x;
				}
				else
				{
					selectCombine.x = 6;
				}
				selectCombine.y = 6;
				lastSelectCombine = selectCombine;
				addChild(selectCombine);
			}
			this.graphics.clear();
			resetBg(width + 12,height + 12);
		}
		
		override public function open() : void
		{
			this.defaultX = GameState.GAME_WIDTH - this.width >> 1;
			this.defaultY = GameState.GAME_HEIGHT - 180;
			
			super.open();
			
			this.stage.addEventListener(MouseEvent.MOUSE_DOWN,onStageDown);
		}
		
		private function onStageDown(event:MouseEvent):void
		{
			close();
			event.target.removeEventListener(MouseEvent.MOUSE_DOWN,onStageDown);
		}
		
		
		override public function close() : void
		{
			super.close(); 
			
			var selectCombine:SelectCombine;
			for (var i:String in selectCombines)
			{
				selectCombine = selectCombines[i];
				selectCombine.destroy();
			}
			selectCombines.length = 0;
			DisplayTool.removeAllChild(this);
		}
	}
}